import express,{Express,Request,Response} from 'express';
import cors from 'cors';
import path from 'path';

const app:Express = express();
const port = 3000;

app.use(cors());
app.use(express.static(path.join(__dirname,'../../project-ts/build')));

// 处理所有其他请求到前端
app.get('*',(req:Request,res:Response)=>{
    res.sendFile(path.join(__dirname,'../../project-ts/build/index.html'));
})

app.get('/getData',(req:Request,res:Response)=>{
    res.send({
        data:"hello world"
    });
})

app.listen(port,()=>{
    console.log(`Server is running at http://localhost:${port}`);
})